import React, { Component } from 'react'
import qs from 'qs'
const data = [
  {
    id: '01',
    content: '你好，世界',
  },
  {
    id: '02',
    content: '你好，中国',
  },
  {
    id: '03',
    content: '你好，保定',
  },
]
export default class Detail extends Component {
  render() {
    //1. 接收params传递过来的参数
    // const { id, title } = this.props.match.params

    //2. 接收query传递过来的参数
    // const { search } = this.props.location
    // console.log(qs.parse(search.slice(1)))
    // const { id, title } = qs.parse(search.slice(1))

    // 3. 接收state传来的参数
    const { id, title } = this.props.location.state
    console.log(this.props)
    //通过id 查找data中对应的数据
    const findObj = data.find((detailObj) => {
      return detailObj.id === id
    })
    return (
      <ul>
        <li>{id}</li>
        <li>{title}</li>
        <li>{findObj.content}</li>
      </ul>
    )
  }
}
